<template>
	<div v-loading="loading">
		<!--部署模式-->
		
		
		<el-radio-group  :disabled="readOnly" v-model="formData" @change="changeDeployModel" >
	    <el-radio v-for="item in deployModelList" :key="item.label"  :label="item.sourceData">{{item.label}}</el-radio>
	  </el-radio-group>
		
  		
			
	</div>
</template>

<script>
	import {deploymodels} from "@/service/swagger/AcTemplateController"

export default {
	props: [
		"readOnly", // 是否可编辑
		//"defaultValue", // 0 
	],
	components: {
		
	},
	data() {
		return {
			defaultValue: 0,
			loading : false,
			formData : {
				
			},
			deployModelList : [{
				value : 0,
				label : "单机",
				sourceData : {
					deployModel: 0,
					instCounts: 1,
					id: 5,
					modelName: "集群",
					status: 0,
				}
			}],
		}
	},
	mounted() {
//		if(this.defaultValue){
//			this.formData.deployModel = this.defaultValue ;
//		}
		this.initValue()
	},
	methods: {
		initDefaultValue(v){
			this.defaultValue = v; 
			return this;
		},
		initValue(defaultValue,emit){
			if(defaultValue||defaultValue==0){
				let data = {};
				this.deployModelList.forEach(el=>{
					if(el.sourceData.deployModel==defaultValue){
						data = el;
					}
				})
				this.formData = data.sourceData;
			}else{
				this.formData = this.formData&&this.formData.deployModel?this.formData :( this.defaultValue || this.deployModelList[0].sourceData );
			}
			if(emit){
				this.emitChange()
			}
			return this;
		},
		initdeployModelList(appType){
			this.loading = true;
			deploymodels({
				appType : appType,
			}).then(ret=>{
				let arr = [];
				if(ret&&ret.data&&ret.data.length){
					ret.data.forEach(el=>{
						arr.push({
							value : el.deployModel,
							label : el.modelName,
							sourceData : el ,
						})
					})
				}
				else{
					arr = [{
						value : 0,
						label : "单机",
						sourceData : {
							deployModel: 0,
							instCounts: 1,
							id: 5,
							modelName: "集群",
							status: 0,
						}
					}]
				}
				this.deployModelList = arr;
				this.initValue(this.defaultValue,true);
				this.loading = false;
			})
		},
		changeDeployModel(v){
			this.emitChange();
		},
		
		emitChange(){
			this.$emit("change","deployModel", this.formData , this.deployModelList )
		},
		
	}

}
</script>

<style>
</style>